Welcome to Bryton in three hours.
Hello, everyone, this is lecturer 11 tends to fall across four classification narrow networks by the
end of this lecture, you will be able to develop shallow and deep neural networks using intensive lacross
in Python for a classification problem.
Before we start, I just want to change my run time to run my code on and G.P.A. So to do that, I go
to change random type and then from on, which is just S.P.C.A., I go to a GPU and I can actually use
Hyram.
But I think for this practice standardly would be enough.
I'm going to save it.
Then we are connecting to a G.P.A. and then now it is ready to be used.
So first we need to import some necessary packages like nanpa, responder's, scaling, preprocessing,
and also we need crossette utils.
So just so next year we are going to load the data, split the data into training and testing and calibrate
the inputs and also our outputs into categorical.
In this example, we are using the employees to train and test data that are already available in our
folder sample data.
So this is similar to the previous practices we had.
So I just wanted so to have my data in training calibrator data and test and calibrated training in
categorical format and testing in categorical format.
And this is basically our data.
Then here I'm going to actually run this cell to print for you as some of our data information, including
the total number of data we have for training and testing.
It is about 20000 training data and 10000 testing data.
So our RTT is about one hour, three or thirty three percent.
So the next step here in this cell is the importance of just Rantes importance for us to.
Next, we are defining the parameters of our neural network and in this case we are practicing a deep
neural network Palak deregulation practice.
You can just change it to one layer of the neurons to have a on it.
If we try it with a deep neural network, then you guys can simply change it for a challenge on a network.
So I keep it, Azeez.
And here are my activation functions of different layers that we have here.
So the activation function corresponding to the first neuron.
Second, the neurons certain neuron, and this is the activation function corresponding to my outputs,
which is now softmax.
Softmax is an activation function that you see the equation here.
It is basically computes a probability distribution.
What is the probability of a data point belonging to, say, handwritten number nine or eight or one?
And for each of the classes we have and in this example, because this handwritten digit data, we have
ten classes, Class zero two, class nine, it gives the probability of a particular input data point
belonging to different classes and basically picks the class that has the highest probability of our
data points belonging to.
So this is another kind of activation function that compares for us.
That probability allows function here is not miniskirted error anymore, but we have categorical cross
entropy.
You can look into the cross documentation's and see Adela's functions for classification problems.
But for the time being, we are using these categorical graphs entropy.
Our optimizer is Adam.
We have it for, let's say, one hundred iterations.
Our in this example is one hundred and twenty eight.
We want to shuffle the data for each iteration or époque and then we want to see the outcome of our
iterative procedure.
So our verbose value is one here somewhere around Izell.
And in here we need to construct our neural network and I'm going to expand this cell.
OK, so first we define the platform, our network or model, by calling Desautel across models that
sequential like the practice we had for the regression then similar to the regression we have, defining
and adding all of these dense layers here and defining the unit numbers here, it's exactly the same
as our regression model, the activation function.
And for the first layer of our hidden neuron, we have to define our input dimension or the total number
of neurons in our empoli, which is basically the total number of our machine learning variables and
or attributes.
Then we have our second dinner on the 13th.
And Lauren, we if we had more number of neurons, we would have also another network add here and perhaps
other than here.
And at the end, we are defining the total number of neurons in our Apulia in addition to the last activation
function, which is now is softmax function.
So our optimizer is Adam Val and then our last function is categorical entropy.
But here we are defining another parameter here, which is called.
Metrics.
And we want our metric here to be accurate, and you're defining it in a form of a character within
a list.
I have to do is just run the and our network here is being compassionate.
We can see a summary of our network, but running the cell, the network summary function, and it shows
you how many layers of neural network you have here, how many neurons are in each layer, and also
how many parameters are there in each layer and what is the total number of parameters for training,
which in this case is about 85000 parameters.
Next, we are going to train our network.
This part is also exactly the same as our regression model.
So all we have to do is just run this cell.
So in this cell, we have history.
Again, our input data output data, which is in the form of categorical epochs, batch size, verbose
and shover.
Note that in our last layer here we have ten as the total number of neurons in the last year or Aratula
year because we turn our outputs into categorical or binary form.
That's why we have ten outputs.
So all I have to do is just run, excel and wait while the training is being complicated.
As you see here, we have both loss and also accuracy being printed for us here.
And later we can plot both our loss and also accuracy over the iteration because all of these information
are basically being saved into our history here.
So all I have to do is to wait until this training is being done.
OK, you've reached the 100 iteration or No.
One hundred, as you see, are accuracy of training is 100 percent.
And this is the value corresponding to our loss.
So here we can estimate the output of our testing data by using net that predict function open and close
practices and input the input of our testing data, which is data in testing calibrator.
And then we are getting data estimated testing, but in the domain of categorical.
So let's run this.
You see not just zero one, but some values and also wants to see basically the outcome of our softmax
function and those probabilities.
So for example, here, the probability of our first testing data point belonging to the first class
or Class Zero is that much, which is a very small number compared to the third class or class.
Number two, probabilistically, we are assigning the category of our first testing data point to the
third class or class number two.
Similarly for other examples.
So in order to find the accuracy of our testing, we need to define and accuracy function and that function.
We call it fun, an underlying accuracy, and it receives our estimation data and our testing data.
And they are in a form of categorical.
So here we are using nonpaid.
That count underlined non-zero function and that function counts the total number of non-zero values
in whatever it receives as the input of these count underly non-zero function.
But what is that input?
So that input has two sections, this section and that section.
And first section is minus the second section.
What is the first section?
The first section is our estimated values, which are in this format, the categorical form.
But we are using that ARG max and here we are finding the index of the maximum value across the second
axis or axis number one.
And this way, since our data test categorical if I just show you the shape of it here.
So the shape is like about ten thousand by ten.
So if I actually get the index of each of the rows of these metrics across the axis, number one, for
the value that is maximum, then we basically turn each of the rows from the categorical or binary form
into an integer four.
So for the first one, if you remember, the probability of the third value was the maximum one.
So here again, this is the third value.
The index corresponding to this one is two.
And that is what pops up for the first data point here.
And this guy also computes the arc, Max, for the corresponding integer value of a categorical output
of the actual outputs.
So if these two are different from one another, then the result, end of these subtraction going to
be non-zero.
And if I compute this for all of these ten thousand testing data points, I'm going to have a column
vector of 10000 values that are either zero or not.
So we want to count here the total number of non zeros, and that's the total number of cases that have
not been accurately estimated or the total number of errors once I have.
My total number of data points that have been estimated with error and I can simply compute our error
rate, which is the total number of errors dividing by our total number of data points, which is about
10000.
And then if I say one minus that rate for that error rate, then I can get my accuracy, which is a
value between zero and one.
So I have to do is just run this up.
Now, my function is in my workspace here.
I can call this cell to compute my accuracy.
And I am doing this in a form of a print function which says testing accuracy equals to open and close
carry prices and a percentage sign here and within the formal function.
I have this fine accuracy here, but I have to multiply it by 100 at the end because we want to get
the percentage version of it.
And within this one, accuracy for estimation.
I have my data estimation test in categorical and for the actual output.
I have my data output of testing categorical.
So all I have to do is just run this function.
And it says that the test accuracy is about ninety six point nine five nine percent.
Here we can plot testing real versus estimated values, but not that for classification problems.
We don't have real values.
There are all classes, categories.
They are integer values.
So real versus estimated values do not mean anything.
All we have to do here is to plot our, let's say, lost value or our accuracy value.
I have to change the title here.
This is plotting iterations versus losses and this is plotting iterations versus accuracy to reach the
losses similar to our previous practices.
We need to call history that history open and close brackets.
And we use the key and that is basically within this plot function for us.
We call it modulus.
The font size Y label is an X label is our iteration number and for accuracy we have model accuracy.
Y label is accuracy and iteration number is our X label to call the accuracy.
We are using history that history, but we are using the key accuracy here.
So, so I have to do is just running these two cells.
So this shows us how losses are decreasing across the iterations.
And if we run this one, it shows that how our accuracy is improving through the iterations.
In this lecture, you learn about how to develop a shallow and deep neural networks using tenths of
a cross in Python for classification problem.
In the next lecture, we will learn about how we can increase our python expertise and knowledge on
our own.
Thank you for your attention.
See you all in the next lecture.